package com.zhongke.cotrun.controller;

import com.zhongke.cotrun.common.util.APIResponse;
import com.zhongke.cotrun.model.exception.MyException;
import com.zhongke.cotrun.model.pojo.Report;
import com.zhongke.cotrun.model.resultpackage.CodeMsg;
import com.zhongke.cotrun.service.ReportService;
import com.zhongke.cotrun.shiro.sys.shiro.ShiroUtils;
import com.zhongke.cotrun.shiro.web.entity.WebUserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/Report")
public class ReportController {
    @Autowired
    ReportService reportService;

    /**
     * 新增举报内容
     * @param report
     * @return
     */
    @PostMapping("/insertReport")
    public APIResponse insertReport(Report report) throws MyException {
        WebUserEntity userEntity = ShiroUtils.getWebUser();//用户信息
        if (userEntity == null) {
            throw new MyException(CodeMsg.USER_LOGIN_ERROR);
        }
        report.setLinkUserId(userEntity.getUserId().intValue());
      if(reportService.insertReport(report)){
          return APIResponse.returnSuccess();
      }
      return APIResponse.returnFail(CodeMsg.ADD_ERROR);
    }
}
